package top.haichi.webpaper.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import top.haichi.webpaper.entity.Student;
import top.haichi.webpaper.entity.Teacher;
import top.haichi.webpaper.entity.User;

@Mapper
public interface UserMapper {
    /**
     * 用户名密码查询用户
     * @param user
     * @return
     */
    @Select("select username,status from user where username=#{username} and password=#{password}")
    public User getByUsernameAndPassword(User user);

    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into user (username,password,id) values (#{username},#{password},#{id})")
    public void addUser(User user);

    /**
     * 用户名查询用户
     * @param user
     * @return
     */
    @Select("select username from user where username=#{username}")
    public User getByUsername(User user);

    /**
     * 学号或工号查询用户
     * @param user
     * @return
     */
    @Select("select id from user where id = #{id}")
    public User getById(User user);

    /**
     * 用户名查询用户数据除密码
     * @param user
     * @return
     */
    @Select("select username,status,id from user where username=#{username}")
    public User getUserWithoutPassword(User user);

    /**
     * 用户名查询学生
     * @param user
     * @return
     */
    @Select("select id from user where username = #{username}")
    public Student getStudentByUsername(User user);

    /**
     * 用户名查询老师
     * @param user
     * @return
     */
    @Select("select id from user where username = #{username}")
    public Teacher getTeacherByUsername(User user);
}
